home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 1035 / 1035.xpi / chrome / 1clickweather.jar / content / 1clickweather / js / utils / log.js < prev    next >
Text File  |  2008-10-05  |  2KB  |  65 lines

  1. /* 
  2.  * This class implement doTech methods 
  3.  * used to operate over log file
  4.  */
  5. function doTech_Utility(){
  6.  
  7.     /* 
  8.      * writeLog(Message Text) 
  9.      * Write message direct to log file
  10.      */
  11.     this.writeLog = function(message){
  12.         /* this is the filename */
  13.         var file = "Alpha_LogFile.log";
  14.         
  15.         // Date
  16.         var objDate = new Date();
  17.         
  18.         // add line return
  19.         message = "[ " + objDate.toDateString() + ", " + objDate.toTimeString() + " ] " + message + "\n";
  20.         // message = message + "\n";
  21.             
  22.         // get profile directory
  23.         var filename = Components.classes["@mozilla.org/file/directory_service;1"]
  24.                          .getService(Components.interfaces.nsIProperties)
  25.                          .get("ProfD", Components.interfaces.nsIFile);
  26.     
  27.         filename.append(file);
  28.         
  29.         /* create a stream */
  30.         var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
  31.                                  .createInstance(Components.interfaces.nsIFileOutputStream);
  32.     
  33.         /* if file does not exist, create and put header */
  34.         if(!filename.exists())
  35.             this.writeHeader(filename);        
  36.         
  37.          // use 0x02 | 0x10 to open for appending
  38.          foStream.init(filename,0x02 | 0x10,0664,0); // write, open.
  39.          foStream.write(message,message.length);
  40.          foStream.close();
  41.     }
  42.     
  43.     /* 
  44.      * writeHeader(FileName) 
  45.      * Write header into the log file
  46.      */
  47.     this.writeHeader = function(filename){
  48.         
  49.         var headerText = "/*\n************************************************************";
  50.         headerText += "\nThis file contain information to internal use to \ndoTech team to testing purpose.\n";
  51.         headerText += "\nCreation Date: " + Date().toString();
  52.         headerText += "\nversion: 0.1.0";
  53.         headerText +=  "\n************************************************************ \n*/\n";
  54.         
  55.         
  56.         /* create a stream */
  57.         var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
  58.                                  .createInstance(Components.interfaces.nsIFileOutputStream);
  59.     
  60.          // use 0x02 | 0x8 write, create
  61.          foStream.init(filename,0x02 | 0x08,0664,0); // write, create.
  62.          foStream.write(headerText,headerText.length);
  63.          foStream.close();    
  64.     }
  65. }